#include <iostream>
#include <boost/regex.hpp>

#include "commun.h"
#include "DTDParse.h"

using namespace std;
using namespace boost;

extern int dtddebug;

int main(int argc, char **argv)
{
#ifdef LE_CODE_A_PIERRE
	DTD* dtddoc;
	int err;
#ifdef DTD_DEBUG
  dtddebug = 0	;
#endif
	  err = dtdparse(&dtddoc);
	  if (err != 0) cout << "Parse ended with "<< err << " error(s)" << endl;
        	else  cout << "Parse ended with success" << endl;
	dtddoc->printMe();
#endif

/******* Test des RegExp ***********/
#ifdef LE_CODE_A_SEB

	/* Simulation de rap1 */
	cout << "Code à Séb" << endl;

	Name* prenom = new Name( "prenom", ONE_OR_MORE );
	Name* nom = new Name( "nom", OPTIONNAL );

	Sequence* seq = new Sequence( ONLY_ONE );
	seq->addParticule( prenom );
	seq->addParticule( nom );

	DTDElement* auteur = new DTDElement;
	auteur->setName( "auteur" );
	auteur->setChildren( seq );

	Mixte* resume = new Mixte;
	SimpleName* link = new SimpleName( "link" );
	resume->setName( "resume" );
	resume->addName( link );

	vector<DTDElement*> elements;
	elements.push_back( auteur );
	elements.push_back( resume );

	DTD dtd( elements );
	
	auteur->printMe();
	resume->printMe();

	vector<regex> regexps = dtd.toRegExp();
	for( size_t i = 0; i < regexps.size(); i++ )
	{
		cmatch what;

		if( regex_match( "auteur(prenom,prenom)", what, regexps[i] ) )
		{
			cout << "Matched." << endl;
		}
		else
			cout << "Not matched." << endl;
	}
#endif

#ifdef LE_CODE_A_TRI

/*
------- test des cardinalités

------- element -> done
------- mixte -> done
------- attlist -> todo
*/

        cout << "Code à Tri" << endl;

        Name* p1 = new Name( "name1_PLUS", ONE_OR_MORE );
        Name* p2 = new Name( "name2_QMARK", OPTIONNAL );
	Name* p3 = new Name( "name3_AST", ZERO_OR_MORE );

        Sequence* seq = new Sequence( ONE_OR_MORE );
        seq->addParticule( p1 );
        seq->addParticule( p2 );
	seq->addParticule( p3 );

	Choice* cho = new Choice(OPTIONNAL);
	cho->addParticule( p1 );
	cho->addParticule( p2 );
	cho->addParticule( p3 );

        DTDElement* e1 = new DTDElement;
        e1->setName( "element1" );
        e1->setChildren( seq );

	DTDElement* e2 = new DTDElement;
        e2->setName( "element2" );
        e2->setChildren( cho );

        Mixte* m1 = new Mixte;
        SimpleName* s1 = new SimpleName( "simple1" );
        m1->setName( "mixte1" );
        m1->addName( s1 );

        vector<DTDElement*> elements;
        elements.push_back( e1 );
        elements.push_back( e2 );
	elements.push_back( m1 );

        DTD dtd( elements );

	AttList * aL1 = new AttList( "attList1" );
	Attribut * a1 = new Attribut( "attr1" );
	a1->setCardinality( OPTIONNAL);
	Attribut * a2 = new Attribut( "attr2" );
	a2->setCardinality( ZERO_OR_MORE);

	aL1->addAttribut(a1);
	aL1->addAttribut(a2);


        e1->printMe();
        e2->printMe();
	m1->printMe();
	aL1->printMe();

#endif

  return 0;
}
